import React, { Component } from "react"
import { Alert, Text, View } from "react-native"
import routerId from "../../consts/routerId"
import { palette } from "@/theme/base/palette"
import { inject } from "mobx-react"
import { SportMenuResp } from "../../models/source/response/SportMenuResp"
import { plainToClass } from "class-transformer"
import { SportMenuMap } from "../../models/source/map-ui/SportMenuMap"
import EventRepository from "../../services/api/event/event-repository"

interface P {
  rootStore: any
  history?: any
}

interface S {}

@inject("rootStore")
export class EventScreen extends Component<P, S> {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: "center", alignItems: "center", marginTop: 20 }}>
        <Text
          style={{ padding: 30, backgroundColor: palette.orange }}
          onPress={() => {
            this.props.history.push(routerId.eventList)
          }}
        >
          赛事列表
        </Text>
        <Text
          style={{ padding: 10, margin: 10, backgroundColor: palette.orange }}
          onPress={() => {
            this.loginXj()
          }}
        >
          登陆小金
        </Text>
        <Text
          style={{ padding: 10, margin: 10, backgroundColor: palette.orange }}
          onPress={() => {
            this.getmenu()
          }}
        >
          getmenu
        </Text>
      </View>
    )
  }

  loginXj = () => {
    const { loginStore } = this.props.rootStore
    loginStore.loginAndXJ("766gbbghnn", "qwer1234")
  }

  getmenu = () => {
    EventRepository.getmenu()
      .then((data: any) => {
        const gameData = plainToClass(SportMenuResp, data.data)
        let sportMenuMap = new SportMenuMap(gameData)
        console.log(sportMenuMap.getAllSportCount(1))
      })
      .catch(error => {
        Alert.alert("请求失败", error.toString())
      })
  }
}

export default EventScreen
